package com.learn.step02_conditionals

/**
 *
 *
 * @author: hbliy
 * @date: 2025/7/8 9:37
 */
fun main(args: Array<String>) {
    val name = "Madrigal"
    var healthPoints = 90
    if (healthPoints == 100) {
        println(name + " is in excellent condition!")
    } else if (healthPoints >= 90) {
        println(name + " has a few scratches.")
    } else if (healthPoints >= 75) {
        println(name + " has some minor wounds.")
    } else if (healthPoints >= 15) {
        println(name + " looks pretty hurt.")
    } else {
        println(name + " is in awful condition!")
    }

    // 使用条件表达式
    val healthStatus = if (healthPoints == 100) {
        "is in excellent condition!"
    } else if (healthPoints >= 90) {
        "has a few scratches."
    } else if (healthPoints >= 75) {
        "has some minor wounds."
    } else if (healthPoints >= 15) {
        "looks pretty hurt."
    } else {
        "is in awful condition!"
    }
    println(name + " " + healthStatus)


    // range
    val age = 18;
    if (age in 1..18) {
        println("teenager")
    } else if (age in 19..64) {
        println("adult")
    } else {
        println("elderly")
    }

    // when
    val race = "gnome"
    val faction = when (race) {
        "human" -> "Alliance"
        "gnome" -> "Horde"
        "dwarf" -> "Horde"
        "night elf" -> "Alliance"
        else -> "unknown"
    }
    println(race + "" + faction)

    val healthStatus2 = when (healthPoints) {
        in 0..15 -> "is in awful condition!"
        in 16..74 -> "has some minor wounds."
        in 75..89 -> "has a few scratches."
        else -> {
            println("enter else")
            "is in excellent condition!"
        }
    }
    println(name + " " + healthStatus2)

    //    string 模板
    println("$name $healthStatus2")
    println("Age: $age, status:${if (age > 18) "adult" else "minor"}")
    // Madrigal is in excellent condition!
    // Age: 18, status:minor
}
